import config


class RegisterLoginApi():
    # 获取图片验证码
    @classmethod
    def get_image_code(cls, session, r):
        url = config.Host + f"/common/public/verifycode1/{r}"
        resp = session.get(url)
        return resp

    # 获取短信验证码
    @classmethod
    def get_phone_code(cls, session, phone, imgVerifyCode):
        url = config.Host + "/member/public/sendSms"
        header = {'Content-Type': 'application/x-www-form-urlencoded'}
        body = {'phone': phone, 'imgVerifyCode': imgVerifyCode, 'type': 'reg'}
        resp = session.post(url=url, headers=header, data=body)
        return resp

    # 注册
    @classmethod
    def register(cls, session, phone, password, verifycode, phone_code):
        url = config.Host + "/member/public/reg"
        header = {"Content-Type": "application/x-www-form-urlencoded"}
        body = {'phone': phone, 'password': password, 'verifycode': verifycode,
                'phone_code': phone_code, 'dy_server': 'on', 'invite_phone': ''}
        resp = session.post(url=url, headers=header, data=body)
        return resp

    #   登录
    @classmethod
    def login(cls, session, keywords, password):
        url = config.Host + "/member/public/login"
        header = {'Content-Type': 'application/x-www-form-urlencoded'}
        body = {'keywords': keywords, 'password': password}
        resp = session.post(url=url, headers=header, data=body)
        return resp

    # 查询登录状态
    @classmethod
    def query_login_status(cls, session):
        resp = session.post(url=config.Host + "/member/public/islogin")
        return resp
